home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlibs.zip / MEMREV.C < prev    next >
Text File  |  1993-01-04  |  978b  |  43 lines

  1.  
  2. /*  File   : memrev.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 1 June 1984
  5.     Defines: char *memrev()
  6.  
  7.     memrev(dst, src, len)
  8.     moves len bytes from src to dst, in REVERSE order.  NUL characters
  9.     receive no special treatment, they are moved like the rest.  It is
  10.     to strrev as memcpy is to strcpy.
  11.  
  12.     Note: this function is perfectly happy to reverse a block into the
  13.     same place, memrev(x, x, L) will work.
  14.  
  15.     It will not work for partially overlapping source and destination.
  16.  
  17.     Returns a pointer to the beginning of the dst.
  18. */
  19.  
  20. char *
  21. memrev(dsta, srca, len)
  22. register char *dsta, *srca;
  23.          int len;
  24. {
  25.     char *dstz, *srcz;
  26.     register char t;
  27.     char *result;
  28.  
  29.     result = dsta;
  30.     if (len > 0)
  31.     {
  32.        srcz = srca+len;
  33.        dstz = dsta+len;
  34.        while (srcz > srca) {
  35.            t = *--srcz;
  36.            *--dstz = *srca++;
  37.            *dsta++ = t;
  38.        }
  39.     }
  40.     return result;
  41. }
  42.  
  43.